import * as asyncWx from "../../utils/asyncWx";

Page({
    data:{
        addressDataList:[ //收货地址列表
            {
                id:0,
                name:"王振飞",
                phone:18655536329,
                address:"江苏省南京市雨花台区春江新城一期鸿觉坊18栋一单元601室"
            },
            {
                id:1,
                name:"山海观雾",
                phone:18655536329,
                address:"江苏省南京市雨花台区春江新城一期鸿觉坊18栋一单元601室"
            }
        ]
    },
    // 从微信获取新地址
    async getAddress(){
        let res1:any=await asyncWx.getSetting();
        if(res1.authSetting["scope.address"] || res1.authSetting["scope.address"] === undefined){
            let res2:any=await asyncWx.chooseAddress();
            let obj={
                id:Math.random(),
                name:res2.userName,
                address:res2.provinceName+res2.cityName+res2.countyName+res2.detailInfo,
                phone:res2.telNumber
            };
            this.data.addressDataList.push(obj);
        }else{ //用户之前拒绝过授予权限，先引导用户打开权限页面
            let res3=await asyncWx.openSetting();
            console.log(res3);
        };
        this.setData({
            addressDataList:this.data.addressDataList
        });
    },
    // 点击新增收货地址事件监听
    addAddress(){
        wx.navigateTo({
            url:"/pages/addAddress/index"
        });
    }
});